#include "QAddCourbeDialog.h"

QAddCourbeDialog::QAddCourbeDialog()
{
	layout=new QGridLayout(this);
	legend_layout=new QVBoxLayout();
	hlayout=new QHBoxLayout();

	pb_cancel=new QPushButton(tr("Annuler"));
	pb_ok=new QPushButton(tr("Creer"));

	courbe=new QCVCourbe();
	
	cb_fonction=new QComboBox();
	cb_fonction->addItem(tr("Moyenne"));
	cb_fonction->addItem(tr("Nombre"));
	cb_fonction->addItem(tr("Min"));
	cb_fonction->addItem(tr("Max"));

	sb_col=new QSpinBox(this);	
	sb_col->setPrefix(tr("colonne="));

	QPixmap pix(50,50);	
	pix.fill(QColor(255,255,255));
	pb_color=new QPushButton(QIcon(pix),tr("Couleur..."),this);
		

	name=new QLineEdit("nom");
	axex=new QLineEdit("axe_x");
	axey=new QLineEdit("axe_y");

	gb_legend=new QGroupBox("Legende");
	
	legend_layout->addWidget(pb_color);
	legend_layout->addWidget(name);
	legend_layout->addWidget(axex);
	legend_layout->addWidget(axey);
	gb_legend->setLayout(legend_layout);	

	hlayout->addWidget(pb_cancel);
	hlayout->addWidget(pb_ok);
		
	layout->addWidget(cb_fonction,0,0);
	layout->addWidget(sb_col,1,0);
	layout->addWidget(gb_legend,2,0);
	layout->addLayout(hlayout,3,0);

	connect(name,SIGNAL(textChanged(QString)),this,SLOT(s_name(QString)));
	connect(axex,SIGNAL(textChanged(QString)),this,SLOT(s_axex(QString)));
	connect(axey,SIGNAL(textChanged(QString)),this,SLOT(s_axey(QString)));
	connect(sb_col,SIGNAL(valueChanged(int)),this,SLOT(s_col(int)));
	connect(pb_color,SIGNAL(clicked()),this,SLOT(s_pick_color()));
	connect(cb_fonction,SIGNAL(currentIndexChanged(int)),this,SLOT(s_function(int)));
	connect(pb_cancel,SIGNAL(clicked()),this,SLOT(reject()));
	connect(pb_ok,SIGNAL(clicked()),this,SLOT(accept()));

}

void QAddCourbeDialog::s_col(int value)
{
	courbe->setCol(value);
}

void QAddCourbeDialog::s_pick_color()
{
	QColor color=QColorDialog::getColor();
	courbe->setColor(color);
	
	QPixmap pix(50,50);	
	pix.fill(color);
	pb_color->setIcon(QIcon(pix));
}

void QAddCourbeDialog::s_name(QString s)
{
	courbe->setName(s);
}
void QAddCourbeDialog::s_axex(QString s)
{
	courbe->setlabelx(s);
}
void QAddCourbeDialog::s_axey(QString s)
{
	courbe->setlabely(s);
}

void QAddCourbeDialog::s_function(int func)
{
	courbe->setFunction(func);
}

QCVCourbe * QAddCourbeDialog::getCourbe()
{
	courbe->setCol(sb_col->value());
	courbe->setName(name->text());
	courbe->setlabely(axey->text());
	courbe->setlabelx(axex->text());
	courbe->setFunction(cb_fonction->currentIndex());
	return courbe;
}
